<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="DotSVN.WebSample._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <link rel="stylesheet" type="text/css" href="build/fonts/fonts-min.css" />
    <link rel="stylesheet" type="text/css" href="build/treeview/assets/skins/sam/treeview.css" />

    <script type="text/javascript" src="build/yahoo/yahoo.js"></script>

    <script type="text/javascript" src="build/event/event.js"></script>

    <script type="text/javascript" src="build/connection/connection.js"></script>

    <script type="text/javascript" src="build/treeview/treeview.js"></script>

    <title>Repository</title>
    <link rel="stylesheet" type="text/css" href="assets/css/folders/tree.css">
    <style type="text/css">
        body {margin:0;	padding:0; }
        #expandcontractdiv {border:1px dotted #dedede; background-color:#EBE4F2; margin:0 0 .5em 0; padding:0.4em;}
        #treeDiv1 { background: #fff; padding:1em; margin-top:1em; }
    </style>
    <style type="text/css"> 
	    .icon-file { padding-left: 20px; background: transparent url(assets/img/file.gif) 0 0px no-repeat; } 
	</style>
</head>
<body class=" yui-skin-sam">
    <form id="form1" runat="server">
        <h2 style="margin: 3; border: 3; border-bottom-style: solid; border-bottom-width: 1px;
            border-bottom-color: Gray;">
            &nbsp;&nbsp;&nbsp;Subversion Browser</h2>
        <div>
            <div id="treeDiv1">
            </div>
            <script type="text/javascript">
    YAHOO.DotSVN = function() {
	var tree;
		function loadNodeData(node)  {
			var path = encodeURI(node.data.path);
			var sUrl = "browse.aspx?path=" + path;
			
			//prepare our callback object
			var callback = {
			
				success: function(oResponse) 
				{
					var oResults = eval("(" + oResponse.responseText + ")");
					
					if((oResults.DirEntries) && (oResults.DirEntries.length)) 
					{
						//Result is an array if more than one result, string otherwise
						if(YAHOO.lang.isArray(oResults.DirEntries)) 
						{
							for (var i=0, j=oResults.DirEntries.length; i<j; i++) 
							{
								var tempNode = new YAHOO.widget.TextNode(oResults.DirEntries[i], node, false);
								if(oResults.DirEntries[i].type == "file")
								{
								    tempNode.dynamicLoadComplete = true;
								    tempNode.expaned = true;
								    tempNode.labelStyle = "icon-file"; 
								}
							}
						} 
					}
					node.loadComplete();
				},
				
				failure: function(oResponse) {
					node.loadComplete();
				},

				argument: {
					"node": node
				},
				
				//timeout -- if more than 7 seconds go by, we'll abort
				//the transaction and assume there are no children:
				timeout: 7000
			};

			YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
		}

        function buildTree() {
		   //create a new tree:
		   tree = new YAHOO.widget.TreeView("treeDiv1");
		   
		   //turn dynamic loading on for entire tree:
		   tree.setDynamicLoad(loadNodeData, 1);
		   
		   //get root node for tree:
		   var root = tree.getRoot();
		   var newNode = { "type" : "Directory", "label" : "Root", "path" : "" } ;
		   
	       var tempNode = new YAHOO.widget.TextNode(newNode, root, false);
		   
		   //render tree with these toplevel nodes; all descendants of these nodes
		   //will be generated as needed by the dynamic loader.
		   tree.draw();
		}

	return {
		init: function() {
            buildTree();
        }
	}
} ();

//once the DOM has loaded, we can go ahead and set up our tree:
YAHOO.util.Event.onDOMReady(YAHOO.DotSVN.init, YAHOO.DotSVN,true)

            </script>

        </div>
    </form>
</body>
</html>
